import { Component, ElementRef, Renderer2 } from '@angular/core';
import { ApesField } from './apes-field';
import { Events } from '@core/services/events/Events';
import { ExpressionService } from '@core/services/expression/ExpressionService';
import { SubjectService } from '@core/services/events/subject.service';
import { ApiService } from '@core/services/http/api.service';
@Component({
  selector: 'formly-field-upload',
  template: `
    <upload  [formControl]="formControl"
             [disabled]="to.disabled"
             [showDownload]="to.showDownload"
             [showCarousel]="to.showCarousel"
             [type]="to.type"
             [api]="api"
             [parsing]="parsing"
             [limit]="to.limit"
             [formState]="formState"
             [showPreviewFormatter]="to.showPreviewFormatter"
             [showRemove]="to.showRemove">
    </upload>
  `,
  host: {},
})


export class FormlyFieldUpload extends ApesField {
  api = 'fileserver/upload';
  parsing = 'upload';
  constructor(protected apiService: ApiService, protected events: Events, protected expressionService: ExpressionService, protected subject: SubjectService,
              protected elementRef: ElementRef, protected renderer: Renderer2) {
    super(apiService, events, expressionService, subject);

  }
  ngOnInit(): void {
    if (this.to.hasOwnProperty('api')){
      this.api = this.to.api;
    }
    if (this.to.hasOwnProperty('parsing')){
      this.parsing = this.to.parsing;
    }
  }

}
